﻿using GalaSoft.MvvmLight;
using RssV_m_v.Model;
using System.Collections.ObjectModel;
using System.ServiceModel.Syndication;

namespace RssV_m_v.ViewModel
{
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
       

        /// <summary>
        /// The <see cref="WelcomeTitle" /> property's name.
        /// </summary>
        public const string WelcomeTitlePropertyName = "WelcomeTitle";
        public const string  ListItemTitre ="ListTitre";
        public const string ListItemParis = "ListItemP";
        public const string ListItemLeMonde = "ListItemM";
        public const string ListItemFigaro = "ListItemF";
        public const string TitreProperty = "Titre";

        private string _titre = string.Empty;
        public string Titre
        {
            get
            {
                return _titre;
            }

            set
            {
                if (_titre == value)
                {
                    return;
                }

                _titre = value;
                RaisePropertyChanged(TitreProperty);
            }
        }
        private ObservableCollection<News> _listItemP = new ObservableCollection<News>();
        public ObservableCollection<News> ListItemP
        {
            get
            {
                return _listItemP;
            }
            set
            {
                if (_listItemP == value)
                {
                    return;
                }

                _listItemP = value;
                RaisePropertyChanged(ListItemParis);
            }
        }
        private ObservableCollection<News> _listItemF = new ObservableCollection<News>();
        public ObservableCollection<News> ListItemF
        {
            get
            {
                return _listItemF;
            }
            set
            {
                if (_listItemF == value)
                {
                    return;
                }

                _listItemF = value;
                RaisePropertyChanged(ListItemFigaro);
            }
        }

       /* public void update(SyndicationItemPerso item,string nomJournal)
        {
            if (nomJournal.CompareTo("parisien") == 0)
            {
                _listItemP.Add(item);
                RaisePropertyChanged(ListItemParis);
            
            }
            else if (nomJournal.CompareTo("figaro") == 0)
            {
                _listItemF.Add(item);
                RaisePropertyChanged(ListItemFigaro);
            }
            
        }*/
    
        private ObservableCollection<News> _listItemM = new ObservableCollection<News>();
        public ObservableCollection<News> ListItemM
        {
            get
            {
                return _listItemM;
            }
            set
            {
                if (_listItemM == value)
                {
                    return;
                }

                _listItemM = value;
                RaisePropertyChanged(ListItemLeMonde);
            }
        }
        public void update(News n)
        {
            _listItemM.Add(n);
            RaisePropertyChanged(ListItemLeMonde);
        }
       
 
 
        private string _welcomeTitle = string.Empty;

        /// <summary>
        /// Gets the WelcomeTitle property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string WelcomeTitle
        {
            get
            {
                return _welcomeTitle;
            }

            set
            {
                if (_welcomeTitle == value)
                {
                    return;
                }
                
                _welcomeTitle = value;
                RaisePropertyChanged(WelcomeTitlePropertyName);
            }
        }

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
           /* _dataService = dataService;
            _dataService.GetData(
                (item, error) =>
                {
                    if (error != null)
                    {
                        // Report error here
                        return;
                    }

                  //  WelcomeTitle = item.Title;
                   // ListItem.Add(item.Title);
                });
             */
            RssService rsss = new RssService(this,"parisien");
            rsss.chargerRSS("http://rss.leparisien.fr/leparisien/rss/une.xml");
            RssService figaro = new RssService(this, "figaro");
            figaro.chargerRSS("http://www.lefigaro.fr/rss/figaro_web.xml");
            RssService leMonde = new RssService(this, "leMonde");
            leMonde.chargerRSS("http://rss.lemonde.fr/c/205/f/3050/index.rss");


        }

        ////public override void Cleanup()
        ////{
        ////    // Clean up if needed

        ////    base.Cleanup();
        ////}


    }
}